/*
 * 1484. 交换数组两个元素
 * 给你一个数组和两个索引，交换下标为这两个索引的数字
 * https://www.lintcode.com/problem/swap-two-integers-in-array/description
 * 
 * 样例
 * 给出 [1,2,3,4] index1 = 2, index2 = 3. 交换之后变成 [1,2,4,3]
 * 
 * 2018.06.10 @jeyming
 */
package swap_two_integers_in_array_1484;

public class Swap_two_integers_in_array_1484 {
	/**
	 * @param A: An integer array
	 * @param index1: the first index
	 * @param index2: the second index
	 * @return: nothing
	 */
	public void swapIntegers(int[] A, int index1, int index2) {
		// write your code here
		//方法一：
//		    	int tmp = A[index1];
//		    	A[index1] = A[index2];
//		    	A[index2] = tmp;

		//方法二：
		if(A.length >= 2 && index1 != index2) {
			A[index1] = A[index1] + A[index2];
			A[index2] = A[index1] - A[index2];
			A[index1] = A[index1] - A[index2];
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
